package yxy.game.pm2.command.player;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.bean.currency.CurrencyGroup;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.PlayerMessage;
import yxy.game.pm2.module.CurrencyHandle;
import yxy.game.pm2.module.avatar.AvatarModule;
import yxy.game.pm2.module.avatar.HeadModule;
import yxy.game.pm2.module.avatar.HeadframeModule;
import yxy.game.pm2.module.avatar.TitleModule;

/** 玩家 获取头像类数据 */
@MessageType(proto = Command.PlayerSignType, classtype = PlayerMessage.PlayerSignTypeRequest.class)
public class CMD_PlayerSignType extends Command<PlayerMessage.PlayerSignTypeRequest> {

	@Override
	public void execute(MessageSource messageSource, PlayerMessage.PlayerSignTypeRequest request) {
		String playerCode = messageSource.getTag();
		int type = request.getType();

		PlayerMessage.PlayerSignTypeResponse.Builder response = PlayerMessage.PlayerSignTypeResponse.newBuilder();

		CurrencyType currencyType = CurrencyType.forNumber(type);
		if (currencyType == null || !currencyType.getGroup().equals(CurrencyGroup.SIGN)) {
			send(messageSource, response, Result.ParamError);
			return;
		}

		response.setType(type);
		response.addAllSign(new CurrencyHandle().allSign(playerCode, currencyType));
		switch (currencyType) {
		case CT_头像:
			response.addAllNewfound(HeadModule.newfound(playerCode));
			break;
		case CT_头像框:
			response.addAllNewfound(HeadframeModule.newfound(playerCode));
			break;
		case CT_形象:
			response.addAllNewfound(AvatarModule.newfound(playerCode));
			break;
		case CT_称号:
			response.addAllNewfound(TitleModule.newfound(playerCode));
			break;
		default:
		}

		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, PlayerMessage.PlayerSignTypeResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}